<?php
class Sanpham extends Zend_Db_Table_Abstract{
    protected $_name;
    protected $_primary = 'SanPhamID';

    function __construct() {
        $this->_name = DB_PREFIX . "sanpham";
        parent::__construct();
    }

    public function getColumns() {
        $results = array('SanPhamID', 'MaSanPham', 'TenSanPham', 'SoLuongTrongKho');
        return $results;
    }

    public function getPrimaryKey() {
        $pk = $this->_primary;
        if (is_array($pk)) {
            if (count($pk) > 0)
                return $pk[1]; // array[1] contain column name of primary key
        }
        return $this->_primary;
    }

    public function updateSoLuong($sanPhamID, $soLuongThayDoi = 0) {
        $table_name = $this->_name;
        $primary_key = $this->_primary;
        if($primary_key)
        $primary_key = $primary_key[1];

        $sql = "UPDATE $table_name SET `SoLuongTrongKho` = `SoLuongTrongKho` + $soLuongThayDoi WHERE `SanPhamID` = $sanPhamID";
        $this->_db->query($sql);
    }
}
?>
